// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 

package com.nnee.p_pr.p_activity;

import android.os.Handler;
import android.text.TextUtils;
import com.nnee.p_g.cls_b;
import com.nnee.p_up.c;
import java.io.*;
import java.net.SocketTimeoutException;
import org.apache.http.NoHttpResponseException;
import org.apache.http.conn.ConnectTimeoutException;

// Referenced classes of package com.nnee.p_pr.p_activity:
//            PRISActivityUpdate

class cls_da extends Thread
{

	cls_da(cls_PRISActivityUpdate prisactivityupdate, String s, String s1, String s2, long l, long l1)
    {
        a = prisactivityupdate;
        super();
        b = s;
        c = s1;
        d = l;
        e = l1;
        f = s2;
        g = false;
    }

    private void a(long l, long l1)
    {
        if(l < 0L || l1 < 0L)
            com.nnee.p_g.cls_b.d(com.nnee.p_pr.p_activity.cls_PRISActivityUpdate.c(), "initializeProgressDialog: invalid input");
        else
            com.nnee.p_pr.p_activity.cls_PRISActivityUpdate.c(a, (int)((100L * l1) / l));
    }

    boolean a(String s, BufferedInputStream bufferedinputstream, long l, long l1)
    {
        if(!TextUtils.isEmpty(s) && bufferedinputstream != null && l >= 0L && l1 >= 0L) goto _L2; else goto _L1
_L1:
        boolean flag = false;
_L12:
        return flag;
_L2:
        RandomAccessFile randomaccessfile;
        int i;
        File file = new File(s.substring(0, 1 + s.lastIndexOf("/")));
        File file1;
        byte abyte0[];
        int j;
        long l2;
        int k;
        if(!file.exists())
            try
            {
                file.mkdirs();
            }
            catch(SecurityException securityexception)
            {
                com.nnee.p_g.cls_b.d(com.nnee.p_pr.p_activity.cls_PRISActivityUpdate.c(), (new StringBuilder()).append("unable to create directory required to save file: ").append(s).toString());
                securityexception.printStackTrace();
                flag = false;
                continue; /* Loop/switch isn't completed */
            }
        file1 = new File(s);
        flag = true;
        randomaccessfile = new RandomAccessFile(s, "rw");
        randomaccessfile.seek(file1.length());
        abyte0 = new byte[1024];
        i = 0;
        j = 0;
        l2 = l / 50L;
_L10:
        if(g)
            break MISSING_BLOCK_LABEL_429;
        k = bufferedinputstream.read(abyte0, 0, 1024);
        if(k <= 0)
            break MISSING_BLOCK_LABEL_429;
        randomaccessfile.write(abyte0, 0, k);
        i += k;
        if((long)(i - j) < l2) goto _L4; else goto _L3
_L3:
        if(!PRISActivityUpdate.a()) goto _L6; else goto _L5
_L5:
        PRISActivityUpdate.a(a, (int)(l1 + (long)i), (int)l);
_L8:
        j = i;
        break MISSING_BLOCK_LABEL_125;
_L6:
        com.nnee.p_pr.p_activity.cls_PRISActivityUpdate.c(a, (int)((100L * (l1 + (long)i)) / l));
        if(true) goto _L8; else goto _L7
_L7:
        FileNotFoundException filenotfoundexception;
        filenotfoundexception;
        com.nnee.p_g.cls_b.d(com.nnee.p_pr.p_activity.cls_PRISActivityUpdate.c(), (new StringBuilder()).append("could not open file: ").append(s).toString());
        flag = false;
        if(randomaccessfile != null)
            try
            {
                randomaccessfile.close();
            }
            catch(Exception exception2)
            {
                exception2.printStackTrace();
            }
        continue; /* Loop/switch isn't completed */
_L4:
        if(l1 + (long)i != l) goto _L10; else goto _L9
_L9:
        if(!PRISActivityUpdate.a())
            break MISSING_BLOCK_LABEL_406;
        PRISActivityUpdate.a(a, (int)(l1 + (long)i), (int)l);
          goto _L10
        IOException ioexception;
        ioexception;
        com.nnee.p_g.cls_b.d(com.nnee.p_pr.p_activity.cls_PRISActivityUpdate.c(), (new StringBuilder()).append("saveData: IOException thrown").append(ioexception.getMessage()).toString());
        throw ioexception;
        Exception exception;
        exception;
        Exception exception3;
        if(randomaccessfile != null)
            try
            {
                randomaccessfile.close();
            }
            catch(Exception exception1)
            {
                exception1.printStackTrace();
            }
        throw exception;
        com.nnee.p_pr.p_activity.cls_PRISActivityUpdate.c(a, (int)((100L * (l1 + (long)i)) / l));
          goto _L10
        if(com.nnee.p_pr.p_activity.cls_PRISActivityUpdate.b())
            com.nnee.p_g.cls_b.e(com.nnee.p_pr.p_activity.cls_PRISActivityUpdate.c(), (new StringBuilder()).append("Totally download bytes: ").append(i).toString());
        if(randomaccessfile != null)
            try
            {
                randomaccessfile.close();
            }
            // Misplaced declaration of an exception variable
            catch(Exception exception3)
            {
                exception3.printStackTrace();
            }
        if(true) goto _L12; else goto _L11
_L11:
    }

    public void interrupt()
    {
        g = true;
        super.interrupt();
    }

    public void run()
    {
        BufferedInputStream bufferedinputstream;
        if(PRISActivityUpdate.a())
            PRISActivityUpdate.j(a).sendEmptyMessage(5);
        else
            PRISActivityUpdate.j(a).sendEmptyMessage(1);
        bufferedinputstream = null;
        bufferedinputstream = com.nnee.p_up.cls_c.a(b, d, a);
        if(bufferedinputstream != null) goto _L2; else goto _L1
_L1:
        PRISActivityUpdate.j(a).sendEmptyMessage(3);
        PRISActivityUpdate.j(a).sendEmptyMessage(0x7f0a00dd);
_L7:
        return;
_L2:
        boolean flag;
        PRISActivityUpdate.j(a).sendEmptyMessage(0x7f0a00d3);
        a(e, d);
        flag = a(c, bufferedinputstream, e, d);
        if(g) goto _L4; else goto _L3
_L3:
        boolean flag1;
        PRISActivityUpdate.j(a).sendEmptyMessage(3);
        flag1 = PRISActivityUpdate.a(a, c, f);
        if(com.nnee.p_pr.p_activity.cls_PRISActivityUpdate.b())
            com.nnee.p_g.cls_b.e(com.nnee.p_pr.p_activity.cls_PRISActivityUpdate.c(), (new StringBuilder()).append("_md5 ==").append(f).toString());
        if(!flag || !flag1) goto _L6; else goto _L5
_L5:
        PRISActivityUpdate.j(a).sendEmptyMessage(0x7f0a00d4);
        PRISActivityUpdate.n(a);
_L4:
        if(bufferedinputstream != null)
            try
            {
                bufferedinputstream.close();
            }
            catch(IOException ioexception1)
            {
                ioexception1.printStackTrace();
            }
          goto _L7
_L6:
        if(flag)
            break MISSING_BLOCK_LABEL_259;
        com.nnee.p_g.cls_b.d(com.nnee.p_pr.p_activity.cls_PRISActivityUpdate.c(), "save data failed when download package from net.");
        if(!flag1)
            com.nnee.p_g.cls_b.d(com.nnee.p_pr.p_activity.cls_PRISActivityUpdate.c(), "md5 check failed.");
        android.os.Message message1 = PRISActivityUpdate.j(a).obtainMessage(0x7f0a00d5, (int)d, -1);
        PRISActivityUpdate.j(a).sendMessage(message1);
          goto _L4
        IOException ioexception;
        ioexception;
label0:
        {
            PRISActivityUpdate.j(a).sendEmptyMessage(3);
            if(!(ioexception instanceof cls_NoHttpResponseException) && !(ioexception instanceof cls_ConnectTimeoutException) && !(ioexception instanceof cls_SocketTimeoutException))
                break label0;
            PRISActivityUpdate.j(a).sendEmptyMessage(0x7f0a00e5);
        }
          goto _L7
label1:
        {
            if(!(ioexception instanceof cls_InterruptedIOException))
                break label1;
            com.nnee.g.b.f(com.nnee.p_pr.p_activity.cls_PRISActivityUpdate.c(), "A blocking I/O operation has been interrupted. Ignore this exception.");
        }
          goto _L4
        com.nnee.p_g.cls_b.d(com.nnee.p_pr.p_activity.cls_PRISActivityUpdate.c(), (new StringBuilder()).append("Unknown IOException: ").append(ioexception.toString()).toString());
        android.os.Message message = PRISActivityUpdate.j(a).obtainMessage(0x7f0a00d5, -1, -1);
        PRISActivityUpdate.j(a).sendMessage(message);
          goto _L7
    }

    private static final int h = 1024;
    final PRISActivityUpdate a;
    private String b;
    private String c;
    private long d;
    private long e;
    private String f;
    private boolean g;
}
